package com.liuweiheng.base.utils;

import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.ValidateObjectInputStream;
import jdk.internal.util.xml.impl.Input;

import java.io.*;

public class IoUtil {
    /**
     * 将文件转为 文件流
     * @param file 文件对象
     * @return 文件流对象
     */
    public static FileInputStream toStream(File file) {
        try {
            return new FileInputStream(file);
        } catch (FileNotFoundException e) {
            throw new IORuntimeException(e);
        }
    }

    public static <T> T readObj(InputStream in) {
        try {
            ObjectInputStream oin = in instanceof ObjectInputStream ? (ObjectInputStream) in : new ObjectInputStream(in);
            return (T) oin.readObject();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }



}
